package com.mingmen.canting.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.mingmen.canting.R;
import com.mingmen.canting.model.CommentModel;
import com.mingmen.canting.model.MySimpleData;
import com.mingmen.canting.model.SimpleData;

import java.util.ArrayList;
import java.util.List;

public class PhotoWaiAdapter extends RecyclerView.Adapter<PhotoWaiAdapter.MyHolder> {
    private Context context;
    private List<CommentModel.DataBean> data;
    private OnMyAdapterCallBack callBack;

    public PhotoWaiAdapter(Context context) {
        this.context = context;
        this.data = new ArrayList<>();
    }

    public void setData(List<CommentModel.DataBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public void setCallBack(OnMyAdapterCallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_photowai, null);
        return new MyHolder(view);
    }

    List<String> images = new ArrayList<>();
    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        CommentModel.DataBean dataBean = data.get(position);

        holder.text_commidyName.setText(dataBean.getSupplierName());
        holder.recyclerView.setLayoutManager(new GridLayoutManager(context, 3));

        holder.recyclerView.setAdapter(holder.childAdater);
//            childAdater.setData(data.get(position).getImgs());

        List<CommentModel.DataBean.DetailsBean> detailsBeanList = new ArrayList<>();
        detailsBeanList = data.get(position).getDetails();

        for (int i = 0; i < data.size(); i++) {

        }
        String img1 = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3933355596,669391437&fm=26&gp=0.jpg";
        String img2 = "http://img4.imgtn.bdimg.com/it/u=1445674920,12445384&fm=26&gp=0.jpg";
        String img3 = "http://img4.imgtn.bdimg.com/it/u=482593725,2192787331&fm=26&gp=0.jpg";
        images.add(img1);
        images.add(img2);
        images.add(img3);
        holder.childAdater.setData(images);

        holder.childAdater.setOnChildClick(new ChildAdapter.OnChildClick() {
            @Override
            public void onItemClick(int currentPosition) {
                if (callBack != null) {
//                        callBack.onItemClick(currentPosition, images.get(position).getImgs());
                    callBack.onItemClick(currentPosition, images);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        RecyclerView recyclerView;
        TextView textView;
        TextView text_commidyName;
        ChildAdapter childAdater = new ChildAdapter(context);
        RecyclerView item_one_rv;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_one_tv_title);
            recyclerView = itemView.findViewById(R.id.item_one_rv);
            text_commidyName = itemView.findViewById(R.id.text_commidyName);
            item_one_rv = itemView.findViewById(R.id.item_one_rv);
        }

   /*     public void buildHolder(final int position) {
            textView.setText(data.get(position).getCategory());

        }*/
    }

    public interface OnMyAdapterCallBack {
        void onItemClick(int position, List<String> itemImgs);
    }
}
